<?php
header("Content-Type: text/html; charset=iso-8859-1");
  require_once('include.php');
 entete('equipes');
  $jours = array('lu'=>'lundi',
   				'ma'=>'mardi',
   				'me'=>'mercredi',
   				'je'=>'jeudi',
   				've'=>'vendredi',
   				'sa'=>'samedi');
   $salles = array(
   					'600'=>'Chamb.',
   					'601'=>'Chamb.',
                    '610'=>'P&acirc;les',
                    '620'=>'Corsy',
                    '611'=>'Croix');
$top = 150;
$pm = -600;
$left = 0;
echo "<h1>Occupation des salles de sport</h1>\n";
echo "<div id = 'tableau' style = 'position: relative; width: 600px;'>\n";
$nb_col = 1;
foreach($jours as $id_jour => $nom_jour){
    $left_jour = $left+40;
		foreach($salles as $no_salle => $nom_salle){
			$requete = "select * from entrainements left join equipes on equipe_id = equipes.id where (jour = '$id_jour' and salle = '
			$no_salle')";
			$resultat = ExecRequete($requete);
			$ok=0;
			$salle_heure = array();
			while($sortie = LigneSuivante($resultat)){
			     $corps = '';
				if(!$ok) {$left += 40; $ok = 1;}
				if($sortie->jour == $id_jour && $sortie->nom){
					$heure = $sortie->heure;
					$text = ($sortie->match) ? "match" : "entr.";
                    if(!empty($salle_heure[$heure])) {$corps = "<br /><br /><br />$text $sortie->nom";}
					else $corps = "$text $sortie->nom";
					$salle_heure[$heure] = 1;
				}
				if($heure){
				    $debut = split("h",substr($heure,0,4));
					$fin = split("h",substr($heure,8,12));
					$debut[1] = $debut[1] / 6;
					$fin[1] = $fin[1] / 60;
					$heure_debut = $debut[0]+$debut[1];
					$heure_fin = $fin[0]+$fin[1];
					if($debut[0]>=16) $ajout = $pm;
					else $ajout = -400;
					$top = $ajout+$heure_debut*50;
					$height = ($heure_fin-$heure_debut)*50-5;
					if(ereg("^<br \/>",$corps)) $class = '';
					else $class = $sortie->id_vbcll;
					echo "<div class = '$class' style = 'position: absolute; width: 30px;border: 1px solid #555; z-index: 20;padding: 5px 5px 0 5px; text-align: center;  top: ".$top."px; left: ".$left."px; height: ".$height."px;font-size: 7pt;'><a href = 'equipes.php?id=$sortie->id'>$corps</a></div>\n";
				}
			}
			if($ok){
				echo "<div style = 'position: absolute; top: 25px; left: ".$left."px; width: 38px; height: 475px; z-index: 11;border: 1px solid grey; text-align: center;'><font style = 'font-size: 7pt'>$nom_salle</font></div>\n";		
				$nb_col++;
			} 
	}
	$width = $left-$left_jour+38;
	echo "<div style = 'position: absolute; top: 0; left: ".$left_jour."px; width: ".$width."px; height: 500px; border: 2px solid black; z-index: 11;text-align: center;font-size: 7pt; font-weight: bold;'>$nom_jour</div>\n";
}
$width = $nb_col*40;
echo "<div style = 'position: absolute; top: 50px; left: 0px; width:  ".$width."px; height: 100px; border: 1px dotted #999; text-align: left;font-size: 7pt; font-weight: bold;'>8h00</div>\n";
echo "<div style = 'position: absolute; top: 150px; left: 0px; width: ".$width."px; height: 50px; border: 1px dotted #999; text-align: left; background: #eee;font-size: 7pt; font-weight: bold;'>12h00</div>\n";
echo "<div style = 'position: absolute; top: 200px; left: 0px; width: ".$width."px; height: 50px; border: 1px dotted #999; text-align: left;font-size: 7pt; font-weight: bold;'>16h00</div>\n";
echo "<div style = 'position: absolute; top: 250px; left: 0px; width: ".$width."px; height: 50px; border: 1px dotted #999; text-align: left;font-size: 7pt; font-weight: bold;'>17h00</div>\n";
echo "<div style = 'position: absolute; top: 300px; left: 0px; width: ".$width."px; height: 50px; border: 1px dotted #999; text-align: left;font-size: 7pt; font-weight: bold;'>18h00</div>\n";
echo "<div style = 'position: absolute; top: 350px; left: 0px; width: ".$width."px; height: 50px; border: 1px dotted #999; text-align: left;font-size: 7pt; font-weight: bold;'>19h00</div>\n";
echo "<div style = 'position: absolute; top: 400px; left: 0px; width: ".$width."px; height: 100px; border: 1px dotted #999; text-align: left;font-size: 7pt; font-weight: bold;'>20h00</div>\n";
echo "<div style = 'position: absolute; top: 490px; left: 0px; width: ".$width."px; height: 30px;  text-align: left;font-size: 7pt; font-weight: bold;'>22h00</div>\n";
echo "</div>\n";
pied();
?>
